using System.Collections.Generic;
using UnityEngine.Networking;

namespace ZSW.Framework.Net
{
    public class ZSWF_WebRequestPool
    {
        private readonly Queue<UnityWebRequest> pool;

        public ZSWF_WebRequestPool(int initialCapacity = 10)
        {
            pool = new Queue<UnityWebRequest>(initialCapacity);
        }

        public UnityWebRequest Get()
        {
            UnityWebRequest request;
            if (pool.Count > 0)
            {
                request = pool.Dequeue();
                request.Dispose(); // Reset the request before reuse
            }
            else
            {
                request = new UnityWebRequest();
            }
            return request;
        }

        public void Release(UnityWebRequest request)
        {
            request.Dispose();
            pool.Enqueue(request);
        }
    }
}